<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UFT-8">
<title>管理员管理</title>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<script src="../../hplus/js/jquery.min.js"></script>
<link rel="stylesheet" href="../../ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
<script type="text/javascript" src="../../ztree/js/jquery.ztree.core.js"></script>
<link rel="stylesheet" type="text/css" href="../../easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../../easyui/themes/icon.css">
<link rel="stylesheet" href="animate.min.css">
<script type="text/javascript" src="../../easyui/jquery.easyui.min.js?1=8" charset=uft-8"></script>
<style type="text/css">
	.tabs
	{
		font-family:微软雅黑;
		font-size:14px;
		height: 36px;
		background-color: rgb(224,236,255);
		width: 100%;
	}
	.tab-btn
	{
		float:left;
		margin-top:5px;
		line-height:30px;
		border: 1px solid rgb(186,219,234);
		margin-left:5px;
		height: 30px;
		padding-right: 5px;
		padding-left: 25px;
		border-top-left-radius:0.3em;
		border-top-right-radius:0.3em;
		cursor: pointer;
		color: rgb(26,110,187);
	}
	.tab-btn-active
	{
		border-bottom: 1px solid white;
	}
	
	.form-edit
	{
		border-collapse:collapse;
		width: 100%;
	}
	.form-edit td
	{
		background-color: rgb(241,241,239);
		border: 1px solid rgb(228,226,223);
		padding-left: 5px;
	}
	.btn
	{
		padding-left: 5px;
		padding-right: 5px;
		height: 30px;
		line-height: 30px;
		text-align: center;
		border-radius:5px;
		color: white;
		background-color: rgb(0,197,228);
		cursor: pointer;
		float: left;
		margin:5px 5px 5px 5px;
		font-weight: bold;
	}
	.btn:hover
	{
		background-color: rgb(0,170,228);
	}
	.icon-dandy{
		background:url('icons/1_close.png') no-repeat;
	}
	
</style>
</head>
<body class="easyui-layout animated fadeInRight">
	<div data-options="region:'center'" style="overflow-x:hidden;overflow-y:hidden;padding: 3px;">
		<div id="tt" class="easyui-tabs" style="width: 100%; height: 100%;overflow-x:hidden;overflow-y:hidden;">
			<div title="管理员信息新建" style="padding: 3px">
				<form id="adminForm">
					<table class="form-edit">
						<tr>
							<td width="10%;">
								管理员账号：
							</td>
							<td width="40%">
								<input id="account" class="easyui-textbox" style="width:200px;height:32px">
							</td>
							<td width="10%;">
								管理员密码：
							</td>
							<td width="40%">
								<input id="password" class="easyui-textbox" style="width:200px;height:32px">
							</td>
						</tr>
						<tr>
							<td width="10%;">
								管理员名称：
							</td>
							<td width="40%">
								<input id="name" class="easyui-textbox" style="width:200px;height:32px">
							</td>
							<td width="10%;">
								类型：
							</td>
							<td width="40%">
								<input id="type" class="easyui-textbox" style="width:200px;height:32px">
							</td>
						</tr>
						<tr>
							<td width="10%;">
								状态：
							</td>
							<td width="40%">
								<input id="status" class="easyui-textbox" style="width:200px;height:32px">
							</td>
							<td colspan="2" width="10%;">
							</td>
						</tr>
						<tr>
							<td colspan="4">
								<div>
									<div id="save" class="btn" style="width: 50px;">提交</div>
									<div id="reset" class="btn" style="width: 50px;">重置</div>
								</div>
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div title="管理员信息管理" style="padding: 3px;overflow: hidden;">
				<table id="adminGrid" class="easyui-datagrid"
						data-options="method:'get',rownumbers:true,
						toolbar:toolbar,fit:true,fitColumns:true">
					<thead>
						<tr>
							<th field="ck" checkbox="true"></th>
							<th data-options="field:'id',width:80,hidden:true">id</th>
							<th data-options="field:'account',width:100">管理员账号</th>
							<th data-options="field:'name',width:100">管理员名称</th>
							<th data-options="field:'type',width:100">类别</th>
							<th data-options="field:'status',width:100">状态</th>
						</tr>
					</thead>
				</table>
			</div>
			<div title="管理员信息修改" style="padding: 3px">
				<form id="updateForm">
					<table class="form-edit">
						<tr style="display: none;">
							<td>
								<input id="u_id" class="easyui-textbox" style="width:200px;height:32px">
							</td>
						</tr>
						<tr>
							<td width="10%;">
								管理员账号：
							</td>
							<td width="40%">
								<input id="u_account" class="easyui-textbox" data-options="readonly:true" style="width:200px;height:32px">
							</td>
							<td width="10%;">
								管理员密码：
							</td>
							<td width="40%">
								<input id="u_password" class="easyui-textbox" style="width:200px;height:32px">
							</td>
						</tr>
						<tr>
							<td width="10%;">
								管理员名称：
							</td>
							<td width="40%">
								<input id="u_name" class="easyui-textbox" style="width:200px;height:32px">
							</td>
							<td width="10%;">
								类型：
							</td>
							<td width="40%">
								<input id="u_type" class="easyui-textbox" style="width:200px;height:32px">
							</td>
						</tr>
						<tr>
							<td width="10%;">
								状态：
							</td>
							<td width="40%">
								<input id="u_status" class="easyui-textbox" style="width:200px;height:32px">
							</td>
							<td colspan="2" width="10%;">
							</td>
						</tr>
						<tr>
							<td colspan="4">
								<div>
									<div id="update" class="btn" style="width: 50px;">提交</div>
								</div>
							</td>
						</tr>
					</table>
				</form>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
$(document).ready(function() {
	
	$('#tt').tabs('select', "管理员信息管理");
	
	//查询
	query();
	
});

function query(){
	$.ajax({
        type: "post",
        dataType: "json",
        url: '${ctx}/sysUser/getUserList',
        data:{
        },
        success: function (data) {
        	$('#adminGrid').datagrid('loadData', data);
        },
		error:function(){
		}
    });
	
}

$("#save").on("click",function(){
	$.messager.confirm('确认提示', '确定保存?', function(r){
		if (r){
			$.ajax({
		        type: "post",
		        dataType: "json",
		        url: '${ctx}/sysUser/addUser',
		        data:{
		        	account:$("#account").val(),
		        	password:$("#password").val(),
		        	name:$("#name").val(),
		        	phone:$("#phone").val(),
		        	type:$("#type").val(),
		        	status:$("#status").val()
		        },
		        success: function (data) {
		        	$('#userForm').form('clear');
		        	query();
		        	$.messager.alert('消息',data.msg,'info');
		        },
				error:function(){
				}
		    });
		}
	});
});

$("#update").on("click",function(){
	if($("#u_id").val()==null || $("#u_id").val()==""){
		$.messager.alert('消息',"请选择修改记录",'info');
		return ;
	}
	
	$.messager.confirm('确认提示', '确定修改?', function(r){
		if (r){
			$.ajax({
		        type: "post",
		        dataType: "json",
		        url: '${ctx}/sysUser/updateUser',
		        data:{
		        	id:$("#u_id").val(),
		        	name:$("#u_name").val(),
		        	phone:$("#u_phone").val(),
		        	type:$("#u_type").val(),
		        	status:$("#u_status").val()
		        },
		        success: function (data) {
		        	query();
		        	$.messager.alert('消息',data.msg,'info');
		        },
				error:function(){
				}
		    });
		}
	});
});

$("#reset").on("click",function(){
	$('#adminForm').form('clear');
});

function deleteUsers(){
	var rows = $('#adminGrid').datagrid('getSelections');
	if(rows.length < 1){
		$.messager.alert('消息','请选择一条记录','info');
	}
	
	$.messager.confirm('确认提示', '确定删除?', function(r){
		if (r){
			var userIds = [];
			for(var i=0; i<rows.length; i++){
				userIds.push(rows[i].id);
			}
			$.ajax({
		        type: "post",
		        dataType: "json",
		        url: '${ctx}/sysUser/deleteUsers',
		        data:{
		        	"userIds":userIds.join(",")
		        },
		        success: function (data) {
		        	if(data.status=='1'){
		        		$.messager.alert('消息',data.msg,'info');
		        		query();
		        	}
		        },
				error:function(){
				}
		    });
		}
	});
}

function toUpdate(){
	var rows = $('#adminGrid').datagrid('getSelections');
	if(rows.length < 1){
		$.messager.alert('消息','请选择一条记录','info');
		return;
	}
	if(rows.length > 1){
		$.messager.alert('消息','最多选择一条记录','info');
		return;
	}
	for(var i=0; i<rows.length; i++){
		$("#u_id").textbox('setValue', rows[i].id);
		$("#u_account").textbox('setValue', rows[i].account);
		$("#u_password").textbox('setValue', rows[i].password);
		$("#u_name").textbox('setValue', rows[i].name);
		$("#u_type").textbox('setValue', rows[i].type);
		$("#u_status").textbox('setValue', rows[i].status);
	}
	
	$('#tt').tabs('select', "管理员信息修改");
}

var toolbar = [ {
	text : '查询',
	iconCls : 'icon-search',
	handler : function() {
		query();
	}
},'-', {
	text : '修改',
	iconCls : 'icon-edit',
	handler : function() {
		toUpdate();
	}
}, '-', {
	text : '删除',
	iconCls : 'icon-remove',
	handler : function() {
		deleteUsers();
	}
} ];

</script>
</html>
